<?php
/**
 * User: wanghousheng
 * Date: 2017/8/8
 * Time: 10:38
 */

namespace App\Common;

class Request extends \PhalApi\Request {

    public function getService() {
        // 优先返回自定义格式的接口服务名称
        $service = $this->get('r');
        if (!empty($service)) {
            $namespace = count(explode('/', $service)) == 2 ? 'App.' : '';
            return $namespace . str_replace('/', '.', $service);
        }else{
            $url = $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
            $arr = explode('/', $url);
            array_shift($arr);
            $namespace = count($arr) == 2 ? 'App.' : '';
            return $namespace . str_replace('/', '.', implode('/',$arr));
        }
        return parent::getService();

    }
}